(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.transaction.pay.futureViewController', futureViewController);
	futureViewController.$inject = [ '$scope', 'Constants', 'modalService', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'transactionService' ];
	function futureViewController($scope, Constants, modalService, layoutConfig, validatorConfig, gridService, authService, transactionService) {
		var ctrl = this, txnPayInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.txnPay = {};
		
		ctrl.init = function() {
			var params = {
					txnpayId : txnPayInfo.txnpayId,
					wfItemKey : txnPayInfo.wfItemKey
			};
			return authService.futureView(params).then(function(response) {
				ctrl.txnPay = response.data || txnPayInfo;
			}, angular.noop);
		};
		
		ctrl.process = function() {
			authService.process(ctrl.txnPay).then(approveSuccessful, approveFailed);
		};

		function approveSuccessful(response) {
			modalService.openAcknowledgeDialogs({
				'messages' : [ 'title.dialog.successful.process' ],
				'btnCallback' : {
					'close' : function() {
						$scope.go('cda.eventWf.list');
					}
				},
				'redirections' : [ {
					'name' : 'title.infobar.eventwf.list',
					'state' : 'cda.eventWf.list',
					'params' : {}
				}, {
					'name' : 'title.infobar.transaction.list',
					'state' : 'cda.transaction.list',
					'params' : {}
				}]
			});
		}

		function approveFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
		
	}
})(angular);